package com.wuyou.sso.controller;

import com.wuyou.sso.common.bean.ResultBean;
import com.wuyou.sso.domain.dto.LoginDTO;
import com.wuyou.sso.domain.dto.UsernamePasswordLoginDTO;
import com.wuyou.sso.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * LoginController
 *
 * @Date 2025/4/24 14:38
 * @Author 无忧
 */
@RestController
@RequestMapping(value = "/login")
public class LoginController {


    @Autowired
    private LoginService loginService;

    /**
     * 通过用户名密码登录
     * @param dto
     * @return
     */
    @PostMapping
    public ResultBean<OAuth2AccessToken> loginByUsernamePassword(@RequestBody @Validated LoginDTO dto){


        return ResultBean.ok(loginService.login((UsernamePasswordLoginDTO) dto));
    }


}
